From 73c1d137e51ec6f2fe03cb619335f1f8c4c16973 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Sun, 30 Jul 2006 17:38:41 +0000 Subject: [PATCH] Add new function 'mklocaltime'. Define new consts 'unknown_speed' and 'unknown_course'. --- defs.h | 6 ++++-- util.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/defs.h b/defs.h index bae98af0f..5a3400054 100644 --- a/defs.h +++ b/defs.h @@ -677,6 +677,7 @@ int xasprintf(char **strp, const char *fmt, ...); char *strupper(char *src); char *strlower(char *src); signed int get_tz_offset(void); +time_t mklocaltime(struct tm *t); time_t mkgmtime(struct tm *t); time_t current_time(void); signed int month_lookup(const char *m); @@ -798,8 +799,9 @@ int color_to_bbggrr(char *cname); * A constant for unknown altitude. It's tempting to just use zero * but that's not very nice for the folks near sea level. */ -#define unknown_alt -99999999.0 - +#define unknown_alt -99999999.0 +#define unknown_course -999.0 +#define unknown_speed -999.0 /* * textfile: buffered OS independent (CRLF,NL,CR) text reader */ diff --git a/util.c b/util.c index b61a12cc0..282ed20c2 100644 --- a/util.c +++ b/util.c @@ -25,6 +25,7 @@ #include #include #include +#include static int i_am_little_endian = -1; static int doswap(void); @@ -702,6 +703,26 @@ mkgmtime(struct tm *t) return(result); } +/* + * mklocaltime: same as mktime, but try to recover the "Summer time flag", + * which is evaluated by mktime + */ +time_t +mklocaltime(struct tm *t) +{ + time_t result; + struct tm check = *t; + + check.tm_isdst = 0; + result = mktime(&check); + check = *localtime(&result); + if (check.tm_isdst == 1) { /* DST is in effect */ + check = *t; + check.tm_isdst = 1; + result = mktime(&check); + } + return result; +} /* * A wrapper for time(2) that allows us to "freeze" time for testing. -- 2.30.2